<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vuev2.5.21.js"></script>
</head>
<body>
    <div id="app">
		<com2 @func="show"></com2>
	</div>
	<template id="tmpl">
			<div>
				<h1>这是子组件</h1>
				<input type="button" value="我是子组件的的按钮,点击会触发父组件传递过来的func 方法" @click="myclick">
			</div>
	</template>
    <script>
		//子组件向父组件传递方法
        var com2 = {
			template:'#tmpl',
			data(){
				return{
					sonmsg:{name:'小头儿子',age:6}
				}
			},
			methods:{
				myclick(){
					this.$emit('func',this.sonmsg)
				}
			}
		}
		var vm = new Vue({
			el:"#app",
			data:{
				datamsg:null,
			},
			methods:{
				show(res){
					console.log(data)
					this.datamsg=data
				}
			},
			components:{
				com2
			}
		})
    </script>
</body>
</html>